<?php

class Munit extends CI_Model {
	
	public $table = 'unit';
	public $pri_key="id";


	function __construct()

	{

		parent::__construct();

	}

	
	function delete()

	{

		if (isset($_POST['select_id']))

		{

			foreach($_POST['select_id'] as $id) {

			//	$row = $this->info_from_id($id);

		

				//xoa file

		//		if ($row['avatar'] != 'null') unlink($row['avatar']);

		

				//xoa CSDL

			//	$sql = "DELETE FROM human_resources WHERE id=$id";
				//$delete = array("deleted"=>"1");
				

			
				$this->db->where($this->pri_key, $id);
				$this->db->delete($this->table); 
				//$this->db->query($sql);

			}			

		}

	}	

	public function insert($data)
	{

		if($this->db->insert($this->table,$data))
			return true;
		
		return false;

	}
		function update($data,$id)
	{
		if(is_numeric($id) && $id !='')
		{
			$this->db->where($this->pri_key,$id);
			if($this->db->update($this->table,$data))
				return true;
			return false;
			
		}
		return false;
	}
	
	
	public function info_form_id($id)
	{
		if(is_numeric($id) && $id !="")
		{
		$this->db->where($this->pri_key.' =',$id);
		return $this->db->get($this->table)->result_array();
		}
		else
			return false;
	}
	public function check_name($name,$id="")
	{
		$this->db->where($this->name.' =',$name);
		if($this->db->count_all($this->table) >0)
			return true; // email nay da ton tai va ko su dung duoc
		return false; // co the su dung email nay
	}
	
	
	public function check_email($email)
	{
		$this->db->where('user_email =',$email);
		if($this->db->count_all($this->table) >0)
			return true; // email nay da ton tai va ko su dung duoc
		return false; // co the su dung email nay
			
 	}
	public function list_data($num,$off)
	{
		$this->db->limit($off,$num);
		$this->db->order_by($this->table.".".$this->pri_key, "desc"); 
		if($this->db->count_all($this->table) >0)
			//return $this->db->get($this->table)->result_array();
			{
		
	
	return $this->db->get($this->table)->result_array();
			}
		return false;
	}
	// dem so record 
	function count_all()
	{
		return $this->db->count_all_results($this->table);
	}
	
	


}//end model class





/* End of file mhumans.php */

/* Location: ./system/application/models/mhumans.php */

?>